from common.utils.enum import WorkType, Scene_Type
from . import db
import datetime


class DataCollection(db.Model):
    __tablename__ = "li_data_collection"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    create_time = db.Column(db.DateTime, doc="采集时间", default=datetime.datetime.utcnow())
    update_time = db.Column(db.DateTime, doc="上传时间")
    area = db.Column(db.String(256), doc="省份")
    city = db.Column(db.String(256), doc="城市")
    work_type = db.Column(db.Enum("采集"), server_default="采集", nullable=False)
    project_name = db.Column(db.String(80), doc="工程名")
    course = db.Column(db.Float, doc="采集里程", default=0)
    file_size = db.Column(db.Float, doc="文件大小", default=0)
    file_num = db.Column(db.Integer, doc="文件数量", default=0)
    work_time = db.Column(db.Float, doc="作业时长", default=0)
    weather = db.Column(db.String(256), doc="天气")
    data_scene = db.Column(db.Enum("白天", "夜间"), server_default="白天", nullable=False)
    road_category = db.Column(db.String(256), doc="道路类别")
    collection_place = db.Column(db.String(256), doc="采集地点")
    follow_user = db.Column(db.String(256), doc="跟车人员")
    remarks = db.Column(db.String(256), doc="备注")
    user = db.Column(db.Integer, db.ForeignKey("li_user.id", ondelete="CASCADE"))
    car = db.Column(db.Integer, db.ForeignKey("li_car_info.id", ondelete="CASCADE"))
    deleted = db.Column(db.Boolean, default=False)
    images = db.relationship(
        "CollectionImage",
        backref="collections",
        lazy="dynamic",
        passive_deletes=False,
        cascade="delete",
    )


class CollectionImage(db.Model):
    ___tablename__ = "li_collection_image"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    file = db.Column(db.String(256), default="", doc="文件")
    collection = db.Column(db.Integer, db.ForeignKey("li_data_collection.id", ondelete="CASCADE"))


class ParkingCollection(db.Model):
    __tablename__ = "li_data_parking"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    create_time = db.Column(db.DateTime, doc="采集开始时间")
    collection_type = db.Column(db.Enum("AS", "PPV"), default="PPV", doc="采集类型")
    find_park_time = db.Column(db.DateTime, doc="车位寻找开始时间")
    find_park_end_time = db.Column(db.DateTime, doc="车位寻找结束时间")
    stop_time = db.Column(db.DateTime, doc="泊车结束时间")
    end_time = db.Column(db.DateTime, doc="采集结束时间")
    update_time = db.Column(db.DateTime, doc="上传时间")
    city = db.Column(db.String(256), doc="采集城市")
    collection_place = db.Column(db.String(256), doc="采集地点")
    parking_type = db.Column(db.Enum("室内", "室外"), doc="停车场特征", default="室外")
    follow_user = db.Column(db.String(256), doc="采集人")
    excavate = db.Column(db.Boolean, doc="是否挖掘", default=False)
    place_type = db.Column(db.String(256), doc="车位特征")
    time_type = db.Column(db.String(256), doc="时间特征")
    othen_type = db.Column(db.String(256), doc="其他特征")
    park_user = db.Column(db.String(256), doc="跟车人员")
    park_num = db.Column(db.Integer, doc="泊入车位数量", default=0)
    upload = db.Column(db.Boolean, default=False, doc="是否上传")
    remarks = db.Column(db.String(256), doc="备注")
    user = db.Column(db.Integer, db.ForeignKey("li_user.id", ondelete="CASCADE"))
    car = db.Column(db.Integer, db.ForeignKey("li_car_info.id", ondelete="CASCADE"))
    deleted = db.Column(db.Boolean, default=False)
    images = db.relationship(
        "ParkingCollectionImage",
        backref="parking_collections",
        lazy="dynamic",
        passive_deletes=False,
        cascade="delete",
    )


class ParkingCollectionImage(db.Model):
    ___tablename__ = "li_parking_collection_image"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    file = db.Column(db.String(256), default="", doc="文件")
    parking_collection = db.Column(
        db.Integer, db.ForeignKey("li_data_parking.id", ondelete="CASCADE")
    )
